<template>
  <div class="astm-list">
    <div class="navss cf" v-click="onSelect" v-show="needNav">
      <a :class="{active:showIndex===0}" data-index="0">特色活动</a>
      <a :class="{active:showIndex===1}" data-index="1">安全教育</a>
      <a :class="{active:showIndex===2}" data-index="2">主题班会</a>
      <a :class="{active:showIndex===3}" data-index="3">微阅读</a>
    </div>
    <!--<transition-group :name="showType?'slide-left':'slide-right'"
                      :enter-active-class="'transition-active'"
                      :leave-active-class="'transition-active'">-->
    <div class="content-box">
      <div :class="{show:showIndex===0}" :key="0" class="item" v-click="e=>{goList(e,'getActivityList')}">
        <img :src="getImgUrl(activity.url)" />
        <a>{{activity.title}}</a>
      </div>
      <div :class="{show:showIndex===1}" :key="1" class="item" v-click="e=>{goList(e,'getSafetyEduList')}">
        <img :src="getImgUrl(safety_edu.img_url)" />
        <a>{{safety_edu.title}}</a>
      </div>
      <div :class="{show:showIndex===2}" :key="2" class="item" v-click="e=>{goList(e,'getThemeMeetingList')}">
        <img :src="getImgUrl(theme_meeting.url)" />
        <a>{{theme_meeting.title}}</a>
      </div>
      <div :class="{show:showIndex===3}" :key="3" class="item" v-click="e=>{goList(e,'getMicroReadList')}">
        <img :src="getImgUrl(micro_reading.url)" />
        <a>{{micro_reading.title}}</a>
      </div>
    </div>
    <!--</transition-group>-->
  </div>
</template>

<script>
import Timer from '@/modules/corejs/time/timer'
export default {
  data () {
    return {
      showIndex: 0,
      showType: 0
    }
  },
  props: {
    needNav: {
      type: Boolean,
      default: true
    },
    dataASTM: {
      type: Object,
      default () { return {} }
    }
  },
  computed: {
    activity () {
      return this.dataASTM.activity || {}
    },
    safety_edu () {
      return this.dataASTM.safety_edu || {}
    },
    theme_meeting () {
      return this.dataASTM.theme_meeting || {}
    },
    micro_reading () {
      return this.dataASTM.micro_reading || {}
    }
  },
  mounted () {
    this.timerInit()
  },
  methods: {
    onSelect (e) {
      let index = e.target.dataset.index
      if (index) {
        let { showIndex } = this
        if (showIndex > index) {
          this.showType = 0
        } else {
          this.showType = 1
        }
        this.showIndex = index * 1
        this.timer.start()
      }
    },
    goList (e, type) {
      // e.preventDefault()
      // e.stopPropagation()
      this.$emit('goList', type)
      // this.$router.push({
      //   name: 'temp2list',
      //   params: {
      //     type,
      //     classid: classId
      //   }
      // })
    },
    getImgUrl (url) {
      if (url) {
        return url.split(',')[0]
      }
    },
    timerInit () {
      this.timer = new Timer({
        callBack: this.timeExcu,
        time: 6000
      })
      this.timer.start()
    },
    timeExcu () {
      let { showIndex } = this
      if (++showIndex >= 4) {
        showIndex = 0
      }
      this.showIndex = showIndex
    }
  }
}
</script>

<style scoped>
.astm-list {
  position: relative;
  height: 612px;
  overflow: hidden;
}
.navss a {
  display: block;
  width: 25%;
  height: 60px;
  float: left;
  text-align: center;
  line-height: 60px;
  font-size: 24px;

  border: solid 1px #eee;
  color: #999;
  box-sizing: border-box;
}

.navss .active {
  background-color: #b4a34a;
  color: #fff;
}

.navss a:first-child {
  border-radius: 8px 0 0 8px;
}

.navss a:last-child {
  border-radius: 0 8px 8px 0;
}
.content-box {
  position: relative;
}
.item {
  width: 860px;
  height: 530px;
  /*margin-top: 80px;*/
  position: absolute;
  left: 0;
  top: 10px;
  transform: translate3d(-100%, 0, 0);
  &.show {
    transform: translate3d(0, 0, 0);
  }
}
.item.transition-active {
  position: absolute;
}

.item img {
  width: 860px;
  height: 530px;
  border-radius: 10px;
}

.item a {
  display: block;
  width: 860px;
  height: 50px;
  background-color: rgba(0, 0, 0, 0.3);
  line-height: 50px;
  text-align: center;
  font-size: 28px;
  color: white;
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 20;
  border-radius: 0 0 10px 10px;
}
</style>
